package penguin.masking.asm;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.LocalVariablesSorter;
import penguin.masking.AgentInterceptor;
import penguin.masking.InterceptorConfig;

/**
 * @author wuxh
 * @version 1.0.0
 */
public abstract class CustomMethodVisitor extends MethodVisitor implements AgentInterceptor, Opcodes {

    protected LocalVariablesSorter lvs;

    protected InterceptorConfig agent;

    public CustomMethodVisitor() {
        super(ASM7);
    }

    public void setParentMethodVisitor(MethodVisitor methodVisitor) {
        this.mv = methodVisitor;
    }

    public void setLvs(LocalVariablesSorter lvs) {
        this.lvs = lvs;
    }

    @Override
    public void config(InterceptorConfig agent) {
        this.agent = agent;
    }

    @Override
    public void beforeMethod() {

    }

    @Override
    public void afterMethod() {

    }

    @Override
    public void visitCode() {
        super.visitCode();
        beforeMethod();
    }

    @Override
    public void visitInsn(int opcode) {
        if (opcode == ARETURN) {
            afterMethod();
        }
        mv.visitInsn(opcode);
    }
}
